from threading import Semaphore
from SistemaOperativo.Planificador import Planificador
from Signals.FinPrograma import FinPrograma

class PriorityPlanner(Planificador):
    
    def __init__(self, list = []):
        self.semaphore = Semaphore(1)
        self.ready = list
        
           
    def order(self, kernel): ## Este metodo es privado
        self.ready = sorted(self.ready, key=lambda pid: kernel.PCBT[pid].priority)
        
    def reschedule(self, kernel):
        if len(self.ready)> 0:
            self.order(kernel)
            print("readyTamanio", self.ready.__len__())
            super(PriorityPlanner, self).reschedule(kernel)
        else:
            kernel.interrupt(FinPrograma())
            
    def getQuantum(self):
        return None
    
    